package org.jradweb.core.taglib;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;

import org.jradweb.core.orm.AbstractModel;
/**
 * 
 *
 * Created On Apr 21, 2008
 * @author <a href="mailto:wagzhi@gmail.com">Paul Wang</a>
 * @version $Id: ModelTag.java 149 2008-10-10 03:10:10Z wagzhi $
 */
public class ModelTag extends BaseTag{
	
	private String  var;
	private String  model;
	private String  method;
	private Integer  modelId;
	
	@Override
	public int doEndTag() throws JspException {
		HttpServletRequest req=(HttpServletRequest)pageContext.getRequest();
		
		if(method.equals("list")){
			Class clazz=AbstractModel.getModelClass(model);
			List result=AbstractModel.list(clazz);
			pageContext.setAttribute(var, result);
		}
		else if(method.equals("get")){
			Class clazz=AbstractModel.getModelClass(model);
			AbstractModel result=(AbstractModel)AbstractModel.get(clazz,modelId);
			pageContext.setAttribute(var, result);
		}
		return super.doEndTag();
	}






	public String getVar() {
		return var;
	}



	public void setVar(String var) {
		this.var = var;
	}



	public String getModel() {
		return model;
	}



	public void setModel(String model) {
		this.model = model;
	}



	public String getMethod() {
		return method;
	}



	public void setMethod(String method) {
		this.method = method;
	}

	public Integer getModelId() {
		return modelId;
	}

	public void setModelId(Integer modelId) {
		this.modelId = modelId;
	}




}
